import request from '../utils/request.js'
import apiConfig from '../config/api.js'

// 订单相关接口
export const orderApi = {
	// 创建订单
	createOrder: (data) => {
		return request({
			url: apiConfig.apiList.createOrder,
			method: 'POST',
			data: data,
			needAuth: true // 标记需要认证
		})
	},
	
	// 取消订单
	cancelOrder: (orderId) => {
		return request({
			url: apiConfig.apiList.cancelOrder.replace(':orderId', orderId),
			method: 'PUT',
			needAuth: true // 标记需要认证
		})
	},
	
	// 获取订单列表
	getOrderList: (params = {}) => {
		return request({
			url: apiConfig.apiList.getOrderList,
			method: 'GET',
			params: params,
			needAuth: true // 标记需要认证
		})
	},
	
	// 获取订单详情
	getOrderDetail: (orderId) => {
		return request({
			url: apiConfig.apiList.getOrderDetail.replace(':orderId', orderId),
			method: 'GET',
			needAuth: true // 标记需要认证
		})
	},
	
	// 更新订单状态
	updateOrderStatus: (orderId, data) => {
		return request({
			url: apiConfig.apiList.updateOrderStatus.replace(':orderId', orderId),
			method: 'PUT',
			data: data,
			needAuth: true // 标记需要认证
		})
	},
	
	// 删除订单
	deleteOrder: (orderId) => {
		return request({
			url: apiConfig.apiList.deleteOrder.replace(':orderId', orderId),
			method: 'DELETE',
			needAuth: true // 标记需要认证
		})
	},
	
	// 获取订单统计
	getOrderStats: () => {
		return request({
			url: apiConfig.apiList.getOrderStats,
			method: 'GET',
			needAuth: true // 标记需要认证
		})
	},
	
	// 获取月订单统计
	getMonthlyStats: () => {
		return request({
			url: apiConfig.apiList.getMonthlyStats,
			method: 'GET',
			needAuth: true // 标记需要认证
		})
	},


	// 根据用户ID获取订单数（需要认证）
	getUserOrderCount: (userId) => {
		return request({
			url: apiConfig.apiList.getUserOrderCount.replace(':userId', userId),
			method: 'GET',
			needAuth: true // 标记需要认证
		})
	},
	
	// 根据用户ID和订单状态获取订单列表（需要认证）
	getUserOrdersByStatus: (params) => {
		return request({
			url: apiConfig.apiList.getUserOrdersByStatus,
			method: 'GET',
			data: params,
			needAuth: true // 标记需要认证
		})
	},
	
	// 创建支付宝支付订单
	createAlipayPayment: (orderId) => {
		return request({
			url: apiConfig.apiList.createAlipayPayment,
			method: 'POST',
			data: { orderId },
			needAuth: true
		})
	},
	
	// 检查支付宝支付状态
	checkAlipayStatus: (orderId) => {
		return request({
			url: apiConfig.apiList.checkAlipayStatus.replace(':orderId', orderId),
			method: 'GET',
			needAuth: true
		})
	}

	
}

export default orderApi